package com.pb.web.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.opensymphony.xwork2.ActionSupport;
import com.pb.entity.District;
import com.pb.entity.HouseType;
import com.pb.entity.Street;

public class HouseAction extends ActionSupport {

	private static final long serialVersionUID = 8860356833945086885L;

	/**
	 * 房屋类型
	 */
	private List<HouseType> types;
	/**
	 * 城区街道-级联集合
	 */
	private Map<District, List<Street>> map;

	/**
	 * 获取 types
	 * 
	 * @return types
	 */
	public List<HouseType> getTypes() {
		return types;
	}

	/**
	 * 设置 types
	 * 
	 * @param types
	 *            types
	 */
	public void setTypes(List<HouseType> types) {
		this.types = types;
	}

	/**
	 * 获取 map
	 * 
	 * @return map
	 */
	public Map<District, List<Street>> getMap() {
		return map;
	}

	/**
	 * 设置 map
	 * 
	 * @param map
	 *            map
	 */
	public void setMap(Map<District, List<Street>> map) {
		this.map = map;
	}

	public String addHouse() {
		// 房型信息集合
		types = new ArrayList<HouseType>();
		types.add(new HouseType(1, "一室一厅"));
		types.add(new HouseType(2, "两室一厅"));
		types.add(new HouseType(3, "三室一厅"));

		// 创建两个城区信息
		District district1 = new District(1, "朝阳区");
		District district2 = new District(2, "东城区");

		// 创建三个街道信息
		List<Street> streets1 = new ArrayList<Street>();
		List<Street> streets2 = new ArrayList<Street>();
		Street street1 = new Street(district1, 1, "朝阳1街");
		Street street2 = new Street(district2, 2, "东城1街");
		Street street3 = new Street(district2, 3, "东城2街");

		// 创建相应街道集合，一个地区的街道为一个集合
		streets1.add(street1);
		streets2.add(street2);
		streets2.add(street3);

		map = new HashMap<District, List<Street>>();
		map.put(district1, streets1);
		map.put(district2, streets2);
		return SUCCESS;
	}
}
